// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2010-5-13
// 14:49:05
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for
// new version!
// Decompiler options: packimports(3)
// Source File Name: AuthoritiesAction.java

package com.stnet.web.enterprice.chinamobile;

import java.net.URLDecoder;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.modules.commons.PageAction;
import com.stnet.entity.Authorities;

public class OrderListAction extends PageAction {
	
	/**
	 * 用于提交update表单后，返回编辑前的页面
	 */
	private String _pageNo;

	public OrderListAction() {
		authorities = new Authorities();
	}

	/**
	 * 2代表套餐类型
	 */
	public String execute() throws Exception {
		super.pager = authoritiesManagerDao.findAuthoritiesByType(pageSize, pageNo, "-1", "2");

		authoritiesList = super.pager.getResultList();
		return "success";
	}

	public String view() throws Exception {
		authorities = authoritiesManagerDao.getAuthorities(id);
		return "view";
	}

	public String edit() throws Exception {
		setAuthorities(authoritiesManagerDao.getAuthorities(id));
		return "edit";
	}

	public String checkName() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String name = request.getParameter("name");
		String orgName = request.getParameter("orgName");
		name = URLDecoder.decode(name, "UTF-8");
		orgName = URLDecoder.decode(orgName, "UTF-8");
		if (authoritiesManagerDao.isNameUnique(name, orgName))
			return renderText("true");
		else
			return renderText("false");
	}

	public String checkDisplayName() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String displayName = request.getParameter("displayName");
		String orgName = request.getParameter("orgName");
		displayName = URLDecoder.decode(displayName, "UTF-8");
		orgName = URLDecoder.decode(orgName, "UTF-8");
		if (authoritiesManagerDao.isDisplayNameUnique(displayName, orgName))
			return renderText("true");
		else
			return renderText("false");
	}

	public String update() throws Exception {
		initAuthorities();
		authorities.setAuthoritiesType("2");
		authoritiesManagerDao.updateAuthorities(authorities);
		
		String _paga_No = _pageNo.equals("")||_pageNo==null?"1":_pageNo;
		super.pager = authoritiesManagerDao.findAuthoritiesByType(pageSize, Integer.valueOf(_paga_No), "-1", "2");
		authoritiesList = super.pager.getResultList();
		return "success";
	}

	public String add_page() throws Exception {
		return "add_page";
	}

	public String add() throws Exception {
		initAuthorities();
		authorities.setAuthoritiesType("2");
		authoritiesManagerDao.addAuthorities(authorities);
		return "add";
	}

	public String delete() throws Exception {
		authoritiesManagerDao.deleteAuthorities(id);
		return "delete";
	}

	public void initAuthorities() {
		authorities.setName(name);
		authorities.setDisplayName(displayName);
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Authorities getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Authorities authorities) {
		this.authorities = authorities;
	}

	public List getAuthoritiesList() {
		return authoritiesList;
	}

	public void setAuthoritiesList(List authoritiesList) {
		this.authoritiesList = authoritiesList;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	private Authorities authorities;
	private List authoritiesList;
	private Long id;
	private String name;
	private String displayName;

	public String get_pageNo() {
		return _pageNo;
	}

	public void set_pageNo(String no) {
		_pageNo = no;
	}
}